<?php
namespace app\admin\controller;

use think\facade\View;
use think\facade\Cache;
use think\facade\Session;
use app\admin\model\AuthRule;



class Index extends Base{

    public function initialize()
    {
        parent::initialize();

    }

    public function index(){

        return view();
    }
    public function clear(){
        // $R = app()->getRootPath().'./runtime/';
        $dirArr = [
            app()->getRootPath().'./runtime/admin',
            app()->getRootPath().'./runtime/api',
            app()->getRootPath().'./runtime/cache',
        ];
        $result = [];
        foreach ($dirArr as $value) {
            if ($this->_deleteDir($value)) {
                $result['info'] = '清除缓存成功!';
                $result['status'] = 1;
                $result['url'] = url('index');
            } else {
                $result['info'] = '清除缓存失败!';
                $result['status'] = 0;
                $result['url'] = url('index');
            }
        }
        echo json_encode($result,320);die;
    }
    private function _deleteDir($R)
    {
        if (is_dir($R)) {
            $handle = opendir($R);
            while (($item = readdir($handle)) !== false) {
                if ($item != '.' and $item != '..') {
                    if (is_dir($R . '/' . $item)) {
                        $this->_deleteDir($R . '/' . $item);
                    } else {
                        if (!unlink($R . '/' . $item))
                            die('error!');
                    }
                }
            }
            closedir($handle);
            return rmdir($R);
        }else{
            return true;
        }
        
        
        
    }
    public function main(){
//        $version = Db::query('SELECT VERSION() AS ver');
//        $version = [0=>1];
        $config = Cache::get('main_config');
        if(!$config){
            $config  = [
                'url'             => $_SERVER['HTTP_HOST'],
                'document_root'   => $_SERVER['DOCUMENT_ROOT'],
                'document_protocol'   => $_SERVER['SERVER_PROTOCOL'],
                'server_os'       => PHP_OS,
                'server_port'     => $_SERVER['SERVER_PORT'],
                'server_ip'       => $_SERVER['REMOTE_ADDR'],
                'server_soft'     => $_SERVER['SERVER_SOFTWARE'],
                'server_file'     => $_SERVER['SCRIPT_FILENAME'],
                'php_version'     => PHP_VERSION,
//                'mysql_version'   => $version[0]['ver'],
                'max_upload_size' => ini_get('upload_max_filesize'),
            ];
            Cache::set('main_config',$config,3600);
        }

        View::assign('config', $config);

        return view();
    }



}